<?php

/**
 * This is the model class for table "purchase_requisition".
 *
 * The followings are the available columns in table 'purchase_requisition':
 * @property string $id
 * @property string $purchase_requisition_number
 * @property string $trans_date
 * @property string $id_section
 * @property string $note
 * @property string $id_parts
 * @property string $part_name
 * @property string $part_description
 * @property string $part_specs
 * @property string $qty
 * @property string $uom
 * @property string $expected_received_date
 * @property string $remarks
 * @property integer $status
 * @property string $created
 * @property integer $created_by
 * @property string $modified
 * @property integer $modified_by
 * @property string $budget_number
 * @property string $revised_from
 * @property string $app1_by
 * @property string $app1_date
 * @property string $app2_by
 * @property string $app2_date
 * @property string $app3_by
 * @property string $app3_date
 * @property string $app4_by
 * @property string $app4_date
 * @property string $app5_by
 * @property string $app5_date
 * @property string $app6_by
 * @property string $app6_date
 * @property string $part_code
 * @property double $price
 * @property string $currency
 * @property string $status_po
 * @property string $supplier_code
 * @property string $reject_date
 * @property string $pending_date
 * @property string $budget_price
 * @property string $data_reject_remark
 */
class PurchaseRequisition extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'purchase_requisition';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('status, created_by, modified_by', 'numerical', 'integerOnly'=>true),
			array('price', 'numerical'),
			array('purchase_requisition_number, revised_from', 'length', 'max'=>100),
			array('id_section, uom, budget_number, part_code, currency, status_po, supplier_code', 'length', 'max'=>50),
			array('note, part_name, part_description, part_specs, remarks', 'length', 'max'=>255),
			array('id_parts, qty, app1_by, app2_by, app3_by, app4_by, app5_by, app6_by, budget_price', 'length', 'max'=>19),
			array('data_reject_remark', 'length', 'max'=>250),
			array('trans_date, expected_received_date, created, modified, app1_date, app2_date, app3_date, app4_date, app5_date, app6_date, reject_date, pending_date', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, purchase_requisition_number, trans_date, id_section, note, id_parts, part_name, part_description, part_specs, qty, uom, expected_received_date, remarks, status, created, created_by, modified, modified_by, budget_number, revised_from, app1_by, app1_date, app2_by, app2_date, app3_by, app3_date, app4_by, app4_date, app5_by, app5_date, app6_by, app6_date, part_code, price, currency, status_po, supplier_code, reject_date, pending_date, budget_price, data_reject_remark', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'part' => array(self::BELONGS_TO, 'Parts', 'id_parts'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'purchase_requisition_number' => 'PR. No',
			'trans_date' => 'PR. Date',
			'id_section' => 'Section Requested',
			'note' => 'Note',
			'id_parts' => 'Id Parts',
			'part_name' => 'Part Name',
			'part_description' => 'Part Description',
			'part_specs' => 'Part Specs',
			'qty' => 'Qty',
			'uom' => 'Uom',
			'expected_received_date' => 'Expected Received Date',
			'remarks' => 'Remarks',
			'status' => 'Approval Level',
			'created' => 'Created',
			'created_by' => 'Created By',
			'modified' => 'Modified',
			'modified_by' => 'Modified By',
			'budget_number' => 'Budget Number',
			'revised_from' => 'Revised From',
			'app1_by' => 'App1 By',
			'app1_date' => 'App1 Date',
			'app2_by' => 'App2 By',
			'app2_date' => 'App2 Date',
			'app3_by' => 'App3 By',
			'app3_date' => 'App3 Date',
			'app4_by' => 'App4 By',
			'app4_date' => 'App4 Date',
			'app5_by' => 'App5 By',
			'app5_date' => 'App5 Date',
			'app6_by' => 'App6 By',
			'app6_date' => 'App6 Date',
			'part_code' => 'Part Code',
			'price' => 'Price',
			'currency' => 'Currency',
			'status_po' => 'Status Po',
			'supplier_code' => 'Supplier Code',
			'reject_date' => 'Reject Date',
			'pending_date' => 'Pending Date',
			'budget_price' => 'Budget Price',
			'data_reject_remark' => 'Data Reject Remark',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
		$criteria->condition = "status=0";

		$criteria->compare('id',$this->id,true);
		$criteria->compare('purchase_requisition_number',$this->purchase_requisition_number,true);
		$criteria->compare('trans_date',$this->trans_date,true);
		$criteria->compare('id_section',$this->id_section,true);
		$criteria->compare('note',$this->note,true);
		$criteria->compare('id_parts',$this->id_parts,true);
		$criteria->compare('part_name',$this->part_name,true);
		$criteria->compare('part_description',$this->part_description,true);
		$criteria->compare('part_specs',$this->part_specs,true);
		$criteria->compare('qty',$this->qty,true);
		$criteria->compare('uom',$this->uom,true);
		$criteria->compare('expected_received_date',$this->expected_received_date,true);
		$criteria->compare('remarks',$this->remarks,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('created',$this->created,true);
		$criteria->compare('created_by',$this->created_by);
		$criteria->compare('modified',$this->modified,true);
		$criteria->compare('modified_by',$this->modified_by);
		$criteria->compare('budget_number',$this->budget_number,true);
		$criteria->compare('revised_from',$this->revised_from,true);
		$criteria->compare('app1_by',$this->app1_by,true);
		$criteria->compare('app1_date',$this->app1_date,true);
		$criteria->compare('app2_by',$this->app2_by,true);
		$criteria->compare('app2_date',$this->app2_date,true);
		$criteria->compare('app3_by',$this->app3_by,true);
		$criteria->compare('app3_date',$this->app3_date,true);
		$criteria->compare('app4_by',$this->app4_by,true);
		$criteria->compare('app4_date',$this->app4_date,true);
		$criteria->compare('app5_by',$this->app5_by,true);
		$criteria->compare('app5_date',$this->app5_date,true);
		$criteria->compare('app6_by',$this->app6_by,true);
		$criteria->compare('app6_date',$this->app6_date,true);
		$criteria->compare('part_code',$this->part_code,true);
		$criteria->compare('price',$this->price);
		$criteria->compare('currency',$this->currency,true);
		$criteria->compare('status_po',$this->status_po,true);
		$criteria->compare('supplier_code',$this->supplier_code,true);
		$criteria->compare('reject_date',$this->reject_date,true);
		$criteria->compare('pending_date',$this->pending_date,true);
		$criteria->compare('budget_price',$this->budget_price,true);
		$criteria->compare('data_reject_remark',$this->data_reject_remark,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return PurchaseRequisition the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
